package com.serene.authority.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serene.authority.admin.entity.MyUserJob;
import com.serene.authority.admin.mapper.UserJobMapper;
import com.serene.authority.admin.service.UserJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author serence
 * @date 2021/5/8 21:30
 */

@Service
public class UserJobServiceImpl extends ServiceImpl<UserJobMapper, MyUserJob> implements UserJobService {

    @Autowired
    private UserJobMapper userJobMapper;

    /**
     * 通过岗位ID查询岗位使用数量
     *
     * @param jobId 岗位id
     * @return
     */
    @Override
    public Integer queryUserJobCountByJobId(Integer jobId) {
        QueryWrapper<MyUserJob> wrapper = new QueryWrapper<>();
        wrapper.eq("jobId", jobId);
        return userJobMapper.selectCount(wrapper);
    }


    /**
     * 通过用户ID删除用户和岗位关联
     *
     * @param userId
     * @return
     */
    @Override
    public Integer deleteUserJobCountByUserId(Integer userId) {
        QueryWrapper<MyUserJob> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        return userJobMapper.delete(wrapper);
    }
}
